//
//  WASStarsLevelView.m
//  WASStarsLevel
//
//  Created by 王璋杰 on 16/6/23.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "WASStarsLevelView.h"
NSString* strHalfStar = @"stars.bundle/half_star";
NSString* strFullStar = @"stars.bundle/full_star";
NSString* strEmptyStar = @"stars.bundle/empty_star";
@implementation WASStarsLevelView
- (instancetype)initWithFrame:(CGRect)frame
{
    CGRect rect = CGRectMake(frame.origin.x, frame.origin.y, frame.size.height * 5, frame.size.height);
    self = [super initWithFrame:rect];
    return self;
}

- (void)setFrame:(CGRect)frame
{
    CGRect rect = CGRectMake(frame.origin.x, frame.origin.y, frame.size.height * 5, frame.size.height);
    [super setFrame:rect];
}

- (void)setLevel:(float)level
{
    _level = level;

    for (int i = 0; i < 5; i++) {
        UIImageView* imageView = [[UIImageView alloc] init];
        CGRect rect = CGRectMake(0, 0, self.bounds.size.height, self.bounds.size.height);
        imageView.frame = CGRectOffset(rect, i * self.bounds.size.height, 0);

        if (level > i) {
            if (level < i + 1) {
                //halfstar
                imageView.image = [UIImage imageNamed:strHalfStar];
            }
            else {
                //fullstar
                imageView.image = [UIImage imageNamed:strFullStar];
            }
        }
        else {
            //emptystar
            imageView.image = [UIImage imageNamed:strEmptyStar];
        }
        [self addSubview:imageView];
    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
}
@end
